# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=physfs
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-hg")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-hg")
pkgver=3.0.2
pkgrel=1
pkgdesc="A library to provide abstract access to various archives (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://icculus.org/physfs/"
license=('ZLIB')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-zlib")
options=('strip' 'staticlibs')
source=(https://icculus.org/physfs/downloads/${_realname}-${pkgver}.tar.bz2)
sha256sums=('304df76206d633df5360e738b138c94e82ccf086e50ba84f456d3f8432f9f863')

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DPHYSFS_BUILD_TEST=OFF \
    -DPHYSFS_BUILD_WX_TEST=OFF \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
  install -D -m644 ${srcdir}/physfs-${pkgver}/LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
